package com.milotnt.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.milotnt.mapper.EmployeeMapper;
import com.milotnt.pojo.EmployeeEntity;
import com.milotnt.service.EmployeeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.List;

@Service
@Slf4j
@Transactional
public class EmployeeServiceImpl extends ServiceImpl<EmployeeMapper, EmployeeEntity> implements EmployeeService {

    @Autowired
    private EmployeeMapper employeeMapper;

    @Override
    public List<EmployeeEntity> findAll() {
        return employeeMapper.findAll();
    }

    @Override
    public Boolean deleteByEmployeeAccount(Long employeeAccount) {
        return employeeMapper.deleteByEmployeeAccount(employeeAccount);
    }

    @Override
    public Boolean insertEmployee(EmployeeEntity employee) {
        Date date = new Date();
        employee.setCreateTime(date);
        String employeeStaff = employee.getStaff().getDescription();
        return employeeMapper.insertEmployee(employee, employeeStaff);
    }

    @Override
    public Boolean updateMemberByEmployeeAccount(EmployeeEntity employee) {
        Date date = new Date();
        employee.setUpdateTime(date);
        String employeeStaff = employee.getStaff().getDescription();
        return employeeMapper.updateMemberByEmployeeAccount(employee, employeeStaff);
    }

    @Override
    public List<EmployeeEntity> selectByEmployeeAccount(Long employeeAccount) {
        return employeeMapper.selectByEmployeeAccount(employeeAccount);
    }

    @Override
    public Integer selectTotalCount() {
        return employeeMapper.selectTotalCount();
    }

    @Override
    public List<EmployeeEntity> selectByStaff(String staff) {
        return employeeMapper.selectByStaff(staff);
    }
}
